//
//  TimeInterval.swift
//  
//
//  Created by tangbl93 on 2021/1/19.
//

import Foundation

public extension TimeInterval {
    
    // minute in seconds
    static var yx_minuteInSeconds: TimeInterval { return 60 }
    // hour in seconds
    static var yx_hourInSeconds: TimeInterval   { return 3600 }
    // day in seconds
    static var yx_dayInSeconds: TimeInterval    { return 86400 }
    // week in seconds
    static var yx_weekInSeconds: TimeInterval   { return 604800 }
    
    /// convert to date
    var yx_date: Date {
        return Date(timeIntervalSince1970: self)
    }
    
    /// convert to string with format
    func yx_string(with format:String, dateFormatter: DateFormatter = DateFormatter.yx_current) -> String {
        dateFormatter.dateFormat = format
        return dateFormatter.string(from: self.yx_date)
    }
}
